
use core::{ffi::c_void, ptr::null_mut};

use mlibs::cmsis_rtos2::{kernel::os_delay, thread::{Thread, PRIORITY_HIGH, THREAD_DETACHED}};

use crate::{driver::cmd_uart::CMD_UART, proto::{CMD_STATUS, TYPE_NOTIFY}};

static STATUS_TASK: Thread<1024, PRIORITY_HIGH, THREAD_DETACHED> = Thread::const_new();

pub fn start() {
    unsafe {
        STATUS_TASK.create("status_task", run, null_mut());
    }
}

const VERSION: u16 = 0x0006;

extern "C"
fn run(_: *mut c_void) {
    defmt::println!("status run");
    let mut seq = 0;
    loop {
        _ = CMD_UART.send(TYPE_NOTIFY, seq, CMD_STATUS, &VERSION);
        seq = seq.wrapping_add(1);
        os_delay(500);
    }
}
